<?php

namespace app\server\controller;

use app\server\model\Goods as GoodsModel;
use app\server\model\Goodclass;
use app\server\model\GoodsImg;
use app\index\controller\Base;
class Goods extends Base
{
   public function get()
   {
       $data = $this->request->param();
       $res = new GoodsModel();
       $d=$res->with('goodsImg')->where($data['field'],$data['op'],$data['value'])
           ->order($data['order_by'],'desc')
           ->select();
       return $d;
   }
   public function update()
   {
       $data = $this->request->param();
       $res = new GoodsModel();
       return $res->updateModel($data);
   }
   public function delete(){
       $data = $this->request->param();
       $res = new GoodsModel();
       return $res->deleteModel($data);
   }
   public function save(){
       $res = new GoodsModel();
       $data = $this->request->param();
       $good = $res->saveModel($data);
       return $good->goods_id;
   }

   public function getGoodClass(){
       $data = $this->request->param();
       $res = new Goodclass();
       return $res->selectModel($data);
   }
    public function addGoodClass(){
        $data = $this->request->param();
        $res = new Goodclass();
        return $res->saveModel($data);
    }
    public function dGoodClass()
    {
        $data = $this->request->param();
        $res = new Goodclass();
        return $res->deleteModel($data);
    }
    public function buyCountInc(){
        $res = new GoodsModel();
        $data = $this->request->param();
        $res->where([$data['field']=>$data['value']])->setInc('buy_count');
    }
    public function addGoodsImg(){
       $res = new GoodsImg();
       $data = $this->request->param();
       $res ->saveModel($data);
    }
    public function deleteGoodsImg(){
        $res = new GoodsImg();
        $data = $this->request->param();
        $res ->deleteModel($data);
    }
    public function num(){
        $data = $this->request->param();
        $res =new GoodsModel();
        return $res->where($data['field'],$data['op'],$data['value'])->count();
    }
}